package com.hsxxherp.simplify.framework.centext.holdor;

/**
 * TenantHolder 线程中的租户数据
 * <p>
 *     基于jackson 实现
 * </p>
 *
 * @author Mark·虎克 (2486970363@qq.com)
 */
public class TenantHolder {
    private static final ThreadLocal<String> TENANT_ID = new InheritableThreadLocal<>();

    /**
     * 设置当前租户 ID
     * @param tenantId 租户 ID
     */
    public static void setTenantId(String tenantId) {
        clearTenantId();
        TENANT_ID.set(tenantId);
    }

    /**
     * 获取当前租户 ID
     * @return 租户 ID
     */
    public static String getTenantId() {
        return TENANT_ID.get();
    }

    /**
     * 清除当前租户 ID
     */
    public static void clearTenantId() {
        TENANT_ID.remove();
    }
}